package pl.edu.pb.wi.cookbook.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;

import pl.edu.pb.wi.cookbook.util.FullTextSearchUtil;

import com.googlecode.objectify.annotation.Entity;

@Entity
public class User extends FullTextSearch implements Serializable {
    private static final long serialVersionUID = -6869145541093112453L;

    @Id
    private Long id;
    private String login;
    private String password;
    private String email;
    private Date createdAt;
    private Date lastLoginAt;
    private String validationHash;
    private Boolean isValidated;
    private Boolean isAdmin;

    public User() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getLastLoginAt() {
        return lastLoginAt;
    }

    public void setLastLoginAt(Date lastLoginAt) {
        this.lastLoginAt = lastLoginAt;
    }

    public String getValidationHash() {
        return validationHash;
    }

    public void setValidationHash(String validationHash) {
        this.validationHash = validationHash;
    }

    public Boolean isValidated() {
        return isValidated;
    }

    public void setValidated(boolean isValidated) {
        this.isValidated = isValidated;
    }

    public Boolean isAdmin() {
        return isAdmin;
    }

    public void setAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    @Override
    public void updateFts() {
        StringBuilder sb = new StringBuilder(login).append(" ").append(email);

        fts = FullTextSearchUtil.getTokensForIndexingOrQuery(sb.toString(),
                FullTextSearchUtil.MAXIMUM_NUMBER_OF_WORDS_TO_PUT_IN_INDEX);
    }

}
